/*
 * @Author: your name
 * @Date: 2020-07-07 09:50:55
 * @LastEditTime: 2020-07-07 15:50:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \thinkjs-test\src\utils\request.js
 */ 
import axios from 'axios'
// import Qs from 'qs'

// 创建 axios 实例
const service = axios.create({
//   baseURL: '/kmlc', // api base_url
  timeout: 6000 // 请求超时时间
})

const err = (error) => {
  if (error.response) {
    let data = error.response.data
    console.log("------异常响应------",error.response.status)
    switch (error.response.status) {
        case 400:
        console.log("-------err:400 参数异常---------");
        break
      case 403:
        console.log("-------err:403 拒绝访问---------");
        break
      case 500:
        console.log("-------err:500---------");
        break
      case 404:
          console.log("-------err:404 资源未找到---------");
        break
      case 504:
        console.log("-------err:504 网络超时---------");
        break
      case 401:
        console.log("-------err:401 未授权，请重新登录---------");
        break
      default:
        console.log('--------------err:',data)
        break
    }
  }
  return Promise.reject(error&&error.response)
};

// request interceptor
service.interceptors.request.use(config => {

  return config
},(error) => {
  return Promise.reject(error)
})

// response interceptor
service.interceptors.response.use((response) => {
    return response.data
  }, err)



export {
  service as axios
}